Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Math »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Calculate the standard deviation of the following data

Next topic

Split fractional and integer parts of a floating point number

Quick search

Print the floating point from mantissa, exponent pair¶

Print the floating point from mantissa, exponent pair.
Expected output:
Mantissa Exponent Floating point value
——– ——– ——————–
0.70 -3 0.09
0.30 0 0.30
0.50 3 4.00
import math

print('{:^7}  {:^8}  {:^17}'.format('Mantissa', 'Exponent', 'Floating point value'))
print('{:-^8}  {:-^8}  {:-^20}'.format('', '', ''))

for m, e in [ (0.7, -3),
              (0.3,  0),
              (0.5,  3),
              ]:
    x = math.ldexp(m, e)

    print('{:7.2f}  {:7d}  {:7.2f}'.format(m, e, x))

Output:

Mantissa  Exponent  Floating point value
--------  --------  --------------------
   0.70       -3     0.09
   0.30        0     0.30
   0.50        3     4.00

See also

https://www.w3resource.com/python-exercises/math/python-math-exercise-58.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Math »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.